Waybill_List_wm.render = function() {
    var Waybill_List_wm_cache = {};
    var old_idname='';
    var Waybill_List_wm = {

        init: function() {
            var that = this;
            $.ajax({
                url: COMMONURL + 'api/Account/GetSendMeum',
                dataType: 'jsonp',
                jsonp: 'jsonpcallback',
                data: {
                    type: 2,
                    token: $.cookie('token')
                }
            }).done(function(data) {
                var menu = data.menu;
                var compiled = _.template($("#Waybill_List_nav").html());
                var compiled_cont = _.template($("#Waybill_List_cont").html());
                $("#fiHeader").html(compiled(menu));
                $("#myTabContent").html(compiled_cont(menu));

                that.firstaction();
                that.shownaction();
                that.showDeliveryDetail();
                that.showHistoryDetail();
                // todo trigger
                // setTimeout(function(){
                //     $('#topWrap').trigger('click');
                // },1000);

                $('#exampleModal').on('show.bs.modal', function(event) {
                    var button = $(event.relatedTarget),
                        itemid = button.data('itemid'),
                        modal = $(this);
                });
            });



        },
        shownaction: function() {
            $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
                // alert(e.target.href) // newly activated tab
                var idname = $(e.target).attr('href').replace('#', '');
                var index = $('a[data-toggle="tab"]').index($(e.target))
        
                 $.cookie('Waybill_List_index', idname);
                 $.cookie('Waybill_List_point', index);
                if (Waybill_List_wm_cache[idname]) {
               
                    $('#' + idname).html(Waybill_List_wm_cache[idname]);
                } else {
                   
                    $.ajax({
                        url: idname + '.html'
                    }).done(function(data) {
                        Waybill_List_wm_cache[idname] = data;
                        $('#' + idname).html(data);


                    })
                }
            })


        },
        firstaction: function() {
            var firstName=$('a[data-toggle="tab"]').eq(0).attr('href').replace('#', '');
            //var point = location.hash.replace('#','').split("&")[1];
            if($.cookie('Waybill_List_point')!=0 && $.cookie('Waybill_List_point')){
                 if(!!$.cookie('Waybill_List_index')){
                firstName = $.cookie('Waybill_List_index');
                $('a[href="#'+firstName+'"]').tab('show');
                return;
                }
            }
          else{
         
            if($.cookie('Waybill_List_index') && firstName != $.cookie('Waybill_List_index')){
                firstName=$.cookie('Waybill_List_index');
                $('a[href="#'+firstName+'"]').tab('show');
              
            }else{
            
                if (Waybill_List_wm_cache[firstName]) {

                $('#' + firstName).html(Waybill_List_wm_cache[firstName]);
            } else {

                $.ajax({
                    url: firstName + '.html'
                }).done(function(data) {
                    Waybill_List_wm_cache[firstName] = data;
                    $('#' + firstName).html(data);


                })
            }
            }
            
            }
        },
        /**
         * 显示运单详情
         */
        showDeliveryDetail: function() {
            $('#xxtopWrap').click(function(){
                // todo 替换这个事件
                var idname = 'waybill_delivery_detail';

                if (Waybill_List_wm_cache[idname]) {
                    $('#waybill_deliverylist').html(Waybill_List_wm_cache[idname]);
                } else {
                   
                    $.ajax({
                        url: idname + '.html'
                    }).done(function(data) {
                        Waybill_List_wm_cache[idname] = data;
                        $('#waybill_deliverylist').html(data);
                    })
                }
            })
        },
        /**
         * 显示运单详情
         */
        showHistoryDetail: function() {
            $(document).on('click', '.J_show-detail', function(){
                // todo 替换这个事件
                var idname = 'waybill_history_detail';
                var id = $(this).data('id');
                if (Waybill_List_wm_cache[idname]) {
                    $('#waybill_history').html(Waybill_List_wm_cache[idname]);
                } else {
                   
                    $.ajax({
                        url: idname + '.html'
                    }).done(function(data) {
                        Waybill_List_wm_cache[idname] = data;
                        $('#waybill_history').html(data);
                        window.waybill_history_detail.renderDetail(id);
                    })
                }
            })
        }
    }

    Waybill_List_wm.init();

}
